<template>
    <div>
        <div class="crumbs">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item>
                    <i class="el-icon-lx-cascades"></i>跟踪情况
                </el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <div class="container">
            <div class="handle-box">

                <el-select v-model="query.sxStatus" placeholder="事项状态" class="handle-select mr10">
                    <el-option key="1" label="未选择" value=""></el-option>
                    <el-option key="2" label="未审查" value="UN_CHECK"></el-option>
                    <el-option key="3" label="补充资料待复查" value="WAIT_CHECK"></el-option>
                    <el-option key="4" label="已通过" value="PASS"></el-option>
                </el-select>
                <el-select v-model="query.sxUrgency" placeholder="紧急程度" class="handle-select mr10">
                    <el-option key="1" label="未选择" value=""></el-option>
                    <el-option key="2" label="紧急" value="ABNORMAL"></el-option>
                    <el-option key="3" label="正常" value="NORMAL"></el-option>
                </el-select>

                <el-button type="primary" icon="el-icon-search" @click="handleSearch">搜索</el-button>
            </div>
            <el-table
                    :data="tableData"
                    border
                    class="table"
                    ref="multipleTable"
                    header-cell-class-name="table-header"
                    @selection-change="handleSelectionChange"
            >
                <el-table-column type="selection" width="55" align="center"></el-table-column>
                <el-table-column prop="sxId" label="事项ID" width="80" align="center"></el-table-column>
                <el-table-column prop="projectName" label="项目名称"></el-table-column>
                <el-table-column prop="bmName" label="部门"></el-table-column>
                <el-table-column prop="sxUrgency" label="紧急程度"></el-table-column>
                <el-table-column prop="sxStatus" label="事项状态" align="center"
                                 width="100">
                    <template slot-scope="scope">
                        <el-tag
                                :type="scope.row.sxStatus === 'PASS' ? 'success' : 'warn'"
                                close-transition>{{scope.row.sxStatus}}
                        </el-tag>
                    </template>
                </el-table-column>

                <el-table-column prop="sxTime" label="立项时间"></el-table-column>
                <el-table-column label="操作" width="200" align="center">
                    <template slot-scope="scope">
                        <el-button
                                type="text"
                                icon="el-icon-tickets"
                                @click="handDetail(scope.$index, scope.row)"
                        >项目详情
                        </el-button>
                        <el-button
                                type="text"
                                icon="el-icon-edit"
                                @click="handleEdit(scope.$index, scope.row)"
                        >编辑
                        </el-button>
                        <el-button
                                type="text"
                                icon="el-icon-delete"
                                class="red"
                                @click="handleDelete(scope.$index, scope.row)"
                        >回收
                        </el-button>
                    </template>
                </el-table-column>
            </el-table>
            <div class="pagination">
                <el-pagination
                        background
                        layout="prev, pager, next"
                        :current-page="curr"
                        :total="pageTotal"
                        :page-size="5"
                        @current-change="handlePageChange"
                ></el-pagination>
            </div>
        </div>

        <!-- 编辑弹出框 -->
        <el-dialog title="编辑" :visible.sync="editVisible" width="30%">
            <el-form ref="form" :model="form" label-width="70px">
                <el-form-item label="事项ID">
                    <el-input v-model="form.sxId"></el-input>
                </el-form-item>
                <el-form-item label="事项状态">
                    <el-select v-model="form.sxStatus">
                        <el-option key="1" label="未审查" value="UN_CHECK"></el-option>
                        <el-option key="2" label="补充资料待复查" value="WAIT_CHECK"></el-option>
                        <el-option key="3" label="通过" value="PASS"></el-option>
                    </el-select>
                </el-form-item>
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button @click="editVisible = false">取 消</el-button>
                <el-button type="primary" @click="saveEdit">确 定</el-button>
            </span>
        </el-dialog>
        <!-- 项目详情弹出框 -->
        <el-dialog title="项目详情" :visible.sync="projectVisible" width="40%">
            <el-form :inline="true" ref="form" :model="projectForm" label-width="100px">
                <el-form-item label="项目Id">
                    <el-input v-model="projectForm.projectId" disabled="disabled"></el-input>
                </el-form-item>
                <el-form-item label="项目名称">
                    <el-input v-model="projectForm.projectName" disabled="disabled"></el-input>
                </el-form-item>
                <el-form-item label="申请人">
                    <el-input v-model="projectForm.userName" disabled="disabled"></el-input>
                </el-form-item>
                <el-form-item label="联系电话">
                    <el-input v-model="projectForm.userPhone" disabled="disabled"></el-input>
                </el-form-item>
                <el-form-item label="未通过事项">
                    <el-input v-model="projectForm.projectSxTotal" disabled="disabled"></el-input>
                </el-form-item>
                <el-form-item label="行业">
                    <el-input v-model="projectForm.industryName" disabled="disabled"></el-input>
                </el-form-item>
                <el-form-item label="项目强度">
                    <el-input v-model="projectForm.projectMoney" disabled="disabled"></el-input>
                </el-form-item>
                <el-form-item label="合作方式">
                    <el-input v-model="projectForm.projectCooperate" disabled="disabled"></el-input>
                </el-form-item>
                <el-form-item label="建设地点">
                    <el-input v-model="projectForm.countryName" disabled="disabled"></el-input>
                </el-form-item>
                <el-form-item label="项目文件">
                    <el-link type="primary" href="http://tzcjj.liuzhou.gov.cn/zsxm/kyl/" target="_blank">文件地址</el-link>
                </el-form-item>
                <el-form-item label="详细描述" prop="desc">
                    <el-input type="textarea" v-model="projectForm.projectContent"></el-input>
                </el-form-item>
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button @click="projectVisible = false">返回</el-button>
            </span>
        </el-dialog>
    </div>
</template>

<script>
    import {fetchData} from '../../api/index';

    export default {
        name: 'basetable',
        data() {
            return {
                query: {
                    sxStatus: '',
                    sxUrgency: '',
                },
                curr: 1,
                tableData: [],
                multipleSelection: [],
                delList: [],
                editVisible: false,
                projectVisible:false,
                pageTotal: 0,
                projectForm: {
                    projectName: '',
                    projectId: '',
                    projectContent:'',
                    projectSxTotal:'',
                    projectFileAddr:'',
                    industryName:'',
                    userName:'',
                    projectMoney:'',
                    userPhone:'',
                    projectCooperate:'',
                    countryName:''
                },
                form: {
                    sxId: '',
                    sxStatus: '',
                },
                idx: -1,
                id: -1,
            };
        },
        mounted() {
            this.getData({});
        },
        methods: {
            getData(params) {
                var vm = this;
                this.$axios.get('/examine/queryAll', {
                    params: params
                }).then(resp => {
                    console.log(resp.data.data.records);
                    if (resp.data.success) {
                        //页面数据
                        vm.tableData = resp.data.data.records;
                        //总条数
                        vm.pageTotal = resp.data.data.total;
                        //当前页
                        vm.curr = resp.data.data.current;
                    }
                })

            },
            // 触发搜索按钮
            handleSearch() {
                var q = this.query;
                var vm = this;
                var params = {sxStatus: q.sxStatus, sxUrgency: q.sxUrgency}
                this.getData(params);
            },
            // 删除操作
            handleDelete(index, row) {
                var id = row.sxId;
                var vm = this;
                let formData = new FormData();
                formData.append("id", id);

                // 二次确认删除
                this.$confirm('确定要回收吗？', '提示', {
                    type: 'warning'
                })
                    .then(() => {
                        this.$axios.post("/examine/delete", formData).then(resp => {
                                if (resp.data.success) {
                                    this.$message.success('回收成功');
                                    this.tableData.splice(index, 1);
                                } else {
                                    this.$message.error(resp.data.message);
                                }
                            }
                        )

                    })
            },
            // 多选操作
            handleSelectionChange(val) {
                this.multipleSelection = val;
            },
            delAllSelection() {
                const length = this.multipleSelection.length;
                let str = '';
                this.delList = this.delList.concat(this.multipleSelection);
                for (let i = 0; i < length; i++) {
                    str += this.multipleSelection[i].name + ' ';
                }
                this.$message.error(`删除了${str}`);
                this.multipleSelection = [];
            },
            //项目详情
            handDetail(index, row) {
                this.form = row;
                this.projectVisible = true;
                var params = {sxId: this.form.sxId};
                this.$axios.get('/examine/projectInfo', {params: params}).then(resp => {
                    console.log(resp.data.data)
                        this.projectForm = resp.data.data;
                })

            },
            // 编辑操作
            handleEdit(index, row) {
                this.form = row;
                this.editVisible = true;
            },
            // 保存编辑
            saveEdit() {
                this.editVisible = false;
                var f = this.form;
                let formData = new FormData();
                formData.append("sxId", f.sxId);
                formData.append("sxStatus", f.sxStatus);
                this.$axios.post('/examine/update', formData).then(resp => {
                    if (resp.data.success) {
                        this.$message.success(`修改第 ${this.idx + 1} 行成功`);
                        this.$set(this.tableData, this.idx, this.form);
                    }
                })
            },
            // 分页导航
            handlePageChange(curr) {
                var f = this.query;
                var params = {
                    sxStatus: f.sxStatus,
                    sxUrgency: f.sxUrgency,
                    pageIndex: curr,
                }
                this.getData(params);
            }
        }
    };
</script>

<style scoped>
    .handle-box {
        margin-bottom: 20px;
    }

    .handle-select {
        width: 120px;
    }

    .handle-input {
        width: 300px;
        display: inline-block;
    }

    .table {
        width: 100%;
        font-size: 14px;
    }

    .red {
        color: #ff0000;
    }

    .mr10 {
        margin-right: 10px;
    }

</style>
